/*
* pps_bom
*/
package com.pitop.project.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.project.entity.ProjectLog;
import com.pitop.project.service.ProjectLogSV;

/**
 * 项目变更日志 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/projectLog")
@Slf4j
@Api(value = "项目变更日志控制器", description = "项目变更日志控制器")
public class ProjectLogCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ProjectLogSV projectLogSV;

    /**
     * 查询ProjectLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectLog一个详情信息", notes = "查询ProjectLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ProjectLog load(Long id) {
        if (id == null) {
            return null;
        }
        ProjectLog projectLog = projectLogSV.load(id);
        log.info(JSON.toJSONString(projectLog));
        return projectLog;
    }


    /**
     * 根据条件id查询ProjectLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ProjectLog一个详情信息", notes = "查询ProjectLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ProjectLog loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ProjectLog projectLog = projectLogSV.loadById(id);
        log.info(JSON.toJSONString(projectLog));
        return projectLog;
    }


    /**
     * 查询ProjectLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectLog信息集合", notes = "查询ProjectLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ProjectLog> list(@RequestBody @ApiIgnore ProjectLog projectLog, Integer curPage, Integer pageSize) {
        Page<ProjectLog> page = new Page<ProjectLog>(pageSize, curPage);
        List<ProjectLog> projectLogs = projectLogSV.list(projectLog, page.genRowStart(), page.getPageSize());
        int total = projectLogSV.count(projectLog);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectLogs;
    }

    /**
     * 查询ProjectLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ProjectLog信息集合", notes = "查询ProjectLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ProjectLog> listByPk(Long id, Integer curPage, Integer pageSize) {
        Page<ProjectLog> page = new Page<ProjectLog>(pageSize, curPage);
        List<ProjectLog> projectLogs = projectLogSV.list(id, page.genRowStart(), page.getPageSize());
        int total = projectLogSV.count(id);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return projectLogs;
    }

    /**
     * 统计ProjectLog信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ProjectLog信息数量根据主键", notes = " 统计ProjectLog信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id) {
        return projectLogSV.count(id);
    }

    /**
     * 统计ProjectLog信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ProjectLog信息数量", notes = "统计ProjectLog信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件定义[修改 Update,删除 Delete,创建 Create,复制 Copy,禁用 Stop]", paramType = "query"),
            @ApiImplicitParam(name = "operateCode", value = "操作人编码", paramType = "query"),
            @ApiImplicitParam(name = "operateName", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "日志描述", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ProjectLog projectLog) {
        return projectLogSV.count(projectLog);
    }

    /**
     * 创建ProjectLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ProjectLog", notes = "创建ProjectLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件定义[修改 Update,删除 Delete,创建 Create,复制 Copy,禁用 Stop]", paramType = "query"),
            @ApiImplicitParam(name = "operateCode", value = "操作人编码", paramType = "query"),
            @ApiImplicitParam(name = "operateName", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "日志描述", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public ProjectLog build(@RequestBody @ApiIgnore ProjectLog projectLog) {
        projectLogSV.save(projectLog);
        return projectLog;
    }

    /**
     * 修改ProjectLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ProjectLog", notes = "修改ProjectLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "projectCode", value = "项目编码", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件定义[修改 Update,删除 Delete,创建 Create,复制 Copy,禁用 Stop]", paramType = "query"),
            @ApiImplicitParam(name = "operateCode", value = "操作人编码", paramType = "query"),
            @ApiImplicitParam(name = "operateName", value = "操作人", paramType = "query"),
            @ApiImplicitParam(name = "summary", value = "日志描述", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ProjectLog modify(@RequestBody @ApiIgnore ProjectLog projectLog) {
        projectLogSV.modify(projectLog);
        return projectLog;
    }

    /**
     * 删除ProjectLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ProjectLog", notes = "删除ProjectLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id) {
        projectLogSV.delete(id);
        return BeanRet.create(true, "删除ProjectLog成功");
    }

}
